//获取应用实例
const app = getApp();

Page({
	data: {
    codename: '获取验证码',
    codeId:'',
    cashpwdId:'',
    cashpwdagainId:'',
  },
	onLoad: function() {

  },

  codeInput: function (e) {
    var that = this;
    that.setData({
      codeId: e.detail.value
    })
  },
  cashpwdInput: function (e) {
    var that = this;
    that.setData({
      cashpwdId: e.detail.value
    })
  },
  cashpwdagainInput: function (e) {
    var that = this;
    that.setData({
      cashpwdagainId: e.detail.value
    })
  },

  //发送设置提现密码手机验证码
  getCode:function(){
    this.getCode();
  },

  //发送设置提现密码手机验证码
  getCode: function () {
    var _this = this;
    wx.request({
      url: app.globalData.api + '/index.php/wap/Sms/sendDrawPwdCode',
      data: {
        token: app.globalData.token,
      },
      headers: {
        'platform': ''+app.globalData.platform,
        'version': ''+app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 1) {
          var num = 61;
          var timer = setInterval(function () {
            num--;
            if (num <= 0) {
              clearInterval(timer);
              _this.setData({
                codename: '重新发送',
                disabled: false
              })

            } else {
              _this.setData({
                codename: num + "s"
              })
            }
          }, 1000)
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'success', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }else{
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }
        
      }, fail: function () {

      }
    });
  },

//保存提现密码
  savecashPwd:function(){
    var that=this;
    if (this.data.codeId.length == 0) {
      wx.showToast({
        title: '请输入手机验证码',
        icon: 'none'
      })
      return;
    }
    if (this.data.cashpwdId.length == 0) {
      wx.showToast({
        title: '请设置提现密码',
        icon: 'none'
      })
      return;
    }
    if (this.data.codeId.cashpwdagainId == 0) {
      wx.showToast({
        title: '请设置重复提现密码',
        icon: 'none'
      })
      return;
    }

    wx.request({
      url: app.globalData.api + '/index.php/wap/UserBalance/setDrawPwd',
      data: {
        token: app.globalData.token,//
        code:that.data.codeId,
        pwd1:that.data.cashpwdId,
        pwd2:that.data.cashpwdagainId,
      },
      headers: {
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 1) {
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'success', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
          setTimeout(function () {
            //要延时执行的代码
            wx.navigateBack({
              delta: 1
            })
          }, 1000) //延迟时间 这里是1秒
        }else{
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }
        
      }, fail: function () {

      }
    });
  },

});
